Replace homedir definition with home crate
authorBrian Anderson <banderson@mozilla.com>
Tue, 18 Jul 2017 23:42:51 +0000 (16:42 -0700)
committerBrian Anderson <banderson@mozilla.com>
Wed, 19 Jul 2017 00:25:31 +0000 (17:25 -0700)
Cargo.lock
Cargo.toml
src/cargo/lib.rs
src/cargo/util/config.rs

index 6205be6e6c25add3f37d02ee2b12040f9ec8c2a2..8de474cf1c59a89343706e044ca25218993d8d9e 100644 (file)
@@ -20,6 +20,7 @@ dependencies = [
  "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
  "hamcrest 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "home 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "ignore 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "jobserver 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -332,6 +333,18 @@ name = "hex"
 version = "0.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
+[[package]]
+name = "home"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "scopeguard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "userenv-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "idna"
 version = "0.1.2"
@@ -677,6 +690,11 @@ name = "scoped-tls"
 version = "0.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
+[[package]]
+name = "scopeguard"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
 [[package]]
 name = "semver"
 version = "0.7.0"
@@ -869,6 +887,15 @@ dependencies = [
  "percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "userenv-sys"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "utf8-ranges"
 version = "0.1.3"
@@ -958,6 +985,7 @@ dependencies = [
 "checksum globset 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "feeb1b6840809ef5efcf7a4a990bc4e1b7ee3df8cf9e2379a75aeb2ba42ac9c3"
 "checksum hamcrest 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bf088f042a467089e9baa4972f57f9247e42a0cc549ba264c7a04fbb8ecb89d4"
 "checksum hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6a22814455d41612f41161581c2883c0c6a1c41852729b17d5ed88f01e153aa"
+"checksum home 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9f25ae61099d8f3fee8b483df0bd4ecccf4b2731897aad40d50eca1b641fe6db"
 "checksum idna 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2233d4940b1f19f0418c158509cd7396b8d70a5db5705ce410914dc8fa603b37"
 "checksum ignore 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b3fcaf2365eb14b28ec7603c98c06cc531f19de9eb283d89a3dff8417c8c99f5"
 "checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c"
@@ -999,6 +1027,7 @@ dependencies = [
 "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
 "checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7"
 "checksum scoped-tls 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f417c22df063e9450888a7561788e9bd46d3bb3c1466435b4eccb903807f147d"
+"checksum scopeguard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "59a076157c1e2dc561d8de585151ee6965d910dd4dcb5dabb7ae3e83981a6c57"
 "checksum semver 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fdd61b85a0fa777f7fb7c454b9189b2941b110d1385ce84d7f76efdf1606a85"
 "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
 "checksum serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6a7c6b751a2e8d5df57a5ff71b5b4fc8aaee9ee28ff1341d640dd130bb5f4f7a"
@@ -1023,6 +1052,7 @@ dependencies = [
 "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
 "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
 "checksum url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb819346883532a271eb626deb43c4a1bb4c4dd47c519bd78137c3e72a4fe27"
+"checksum userenv-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d28ea36bbd9192d75bd9fa9b39f96ddb986eaee824adae5d53b6e51919b2f3"
 "checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f"
 "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
 "checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b"
index 263f061de3ce9a34e77d7bae795a84bdfee1f521..8a8f1dc46e5daacf04cd6f113848af79d35f3cfc 100644 (file)
@@ -31,6 +31,7 @@ git2 = "0.6"
 git2-curl = "0.7"
 glob = "0.2"
 hex = "0.2"
+home = "0.3"
 ignore = "^0.2.2"
 jobserver = "0.1.6"
 libc = "0.2"
index 1b96813433bbe0fc6354c82483f306d5ae56c856..bfaf0d1bd965c9144ac27066654f396d49e219c0 100755 (executable)
@@ -19,6 +19,7 @@ extern crate fs2;
 extern crate git2;
 extern crate glob;
 extern crate hex;
+extern crate home;
 extern crate ignore;
 extern crate jobserver;
 extern crate libc;
index 2df174740df483a0109c7305201225a8eae1afe2..ede87eabaa20983abde8be86d704cc8c3063b841 100644 (file)
@@ -757,53 +757,7 @@ impl fmt::Display for Definition {
 }
 
 pub fn homedir(cwd: &Path) -> Option<PathBuf> {
-    let cargo_home = env::var_os("CARGO_HOME").map(|home| {
-        cwd.join(home)
-    });
-    if cargo_home.is_some() {
-        return cargo_home
-    }
-
-    // If `CARGO_HOME` wasn't defined then we want to fall back to
-    // `$HOME/.cargo`. Note that currently, however, the implementation of
-    // `env::home_dir()` uses the $HOME environment variable *on all platforms*.
-    // Platforms like Windows then have *another* fallback based on system APIs
-    // if this isn't set.
-    //
-    // Specifically on Windows this can lead to some weird behavior where if you
-    // invoke cargo inside an MSYS shell it'll have $HOME defined and it'll
-    // place output there by default. If, however, you run in another shell
-    // (like cmd.exe or powershell) it'll place output in
-    // `C:\Users\$user\.cargo` by default.
-    //
-    // This snippet is meant to handle this case to ensure that on Windows we
-    // always place output in the same location, regardless of the shell we were
-    // invoked from. We first check `env::home_dir()` without tampering the
-    // environment, and then afterwards we remove `$HOME` and call it again to
-    // see what happened. If they both returned success then on Windows we only
-    // return the first (with the $HOME in place) if it already exists. This
-    // should help existing installs of Cargo continue using the same cargo home
-    // directory.
-    let home_dir_with_env = env::home_dir().map(|p| p.join(".cargo"));
-    let home_dir = env::var_os("HOME");
-    env::remove_var("HOME");
-    let home_dir_without_env = env::home_dir().map(|p| p.join(".cargo"));
-    if let Some(home_dir) = home_dir {
-        env::set_var("HOME", home_dir);
-    }
-
-    match (home_dir_with_env, home_dir_without_env) {
-        (None, None) => None,
-        (None, Some(p)) |
-        (Some(p), None) => Some(p),
-        (Some(a), Some(b)) => {
-            if cfg!(windows) && !a.exists() {
-                Some(b)
-            } else {
-                Some(a)
-            }
-        }
-    }
+    ::home::cargo_home_with_cwd(cwd).ok()
 }
 
 fn walk_tree<F>(pwd: &Path, mut walk: F) -> CargoResult<()>